package com.demo2do.jit;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;

import java.util.List;

/**
 * Created by wilson on 17/6/25.
 */

public class GasGridViewAdapter extends BaseAdapter {

    /** 上下文对象 */
    private Context context;

    /** girdview 视图参数 */
    private List<String> numbers;

    public GasGridViewAdapter(Context context, List<String> numbers) {
        this.context = context;
        this.numbers = numbers;
    }

    @Override
    public int getCount() {
        return numbers.size();
    }

    @Override
    public Object getItem(int position) {
         return numbers.get(position);
     }

    @Override
    public long getItemId(int position) {
         return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if(convertView == null) {

            convertView = LayoutInflater.from(context).inflate(R.layout.activity_gas_gridviewitem, null);
            holder = new ViewHolder();
            holder.itemButton = (Button) convertView.findViewById(R.id.buttons_gridview_item);
            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();
        }

        holder.itemButton.setText(numbers.get(position));

        return convertView;

    }

    static class ViewHolder {
        public Button itemButton;
    }

}
